<p class="ui-state-default ui-corner-all ui-helper-clearfix"> <?php nadpis() ?></p>
<form method="post" action="index.php?modul=users&action=<?php echo $_GET["subpage"] ?>">
	<input type="hidden" name="id" value="<?php echo $_GET["id"] ?>">
	<table align="center" cellpadding="5">
		<tr>
			<td align="right"><img src="theme/ikonky/user.png" align="absmiddle"> Jméno</td>
			<td><input type="text" name="name" value="<?php if(!is_null($entity)) echo $entity->get_name() ?>" echo class="text ui-widget-content ui-corner-all" style="width: 100%"></td>
			<td>
				<img src="theme/ikonky/help.png" title="Jméno musí mít minimálně 4 znaky a musí být jedinečné.">
			</td>
		</tr>

		<tr>
			<td align="right"><img src="theme/ikonky/key.png" align="absmiddle">
				Heslo
			</td>
			<td>
				<input type="password" name="password" class="text ui-widget-content ui-corner-all" style="width: 100%">
			</td>
			<td>
				<?php 
					if($_GET["subpage"] == "edit_user")
						echo '<img src="theme/ikonky/help.png" title="Heslo musí mít alespon 5 znaků. Pokud nechcete měnit heslo, nechte pole prázdné.">';
					else
						echo '<img src="theme/ikonky/help.png" title="Heslo musí mít alespon 5 znaků."">';
				?>
			</td>
		</tr>

		<tr>
			<td align="right"><img src="theme/ikonky/email.png" align="absmiddle"> E-Mail</td>
			<td><input type="text" name="email" value="<?php if(!is_null($entity)) echo $entity->get_email() ?>" class="text ui-widget-content ui-corner-all" style="width: 100%"></td>
			<td>
				<img src="theme/ikonky/help.png" title="Zadejte email ve správném tvaru - jmeno@domena.tld">
			</td>
		</tr>

		<tr>
			<td align="right"><img src="theme/ikonky/group.png" align="absmiddle"> Skupina</td>
			<td><?php !is_null($entity) ? ranks($entity->get_rank()) : ranks(); ?></td>
			<td>
			</td>
		</tr>
	</table>

	<?php button() ?>

</form>

<?php

function nadpis()
{
	if($_GET["subpage"] == "add_user") echo '<img src="theme/ikonky/user_add.png" align="absmiddle"> Nový uživatel';
	else if($_GET["subpage"] == "edit_user") echo '<img src="theme/ikonky/user_edit.png" align="absmiddle"> Editace uživatele';
}

function button()
{
	if($_GET["subpage"] == "add_user")
	{
		echo '
		<p align="center">
			<button class="button" type="submit">
				<img src="theme/ikonky/user_add.png" align="absmiddle"> Přidat uživatele
			</button>
		</p>';
	}
	else if($_GET["subpage"] == "edit_user")
	{
		echo '
		<p align="center">
			<button class="button" type="submit">
				<img src="theme/ikonky/user_edit.png" align="absmiddle"> Uložit změny
			</button>
		</p>';
	}
}

function ranks($rank = 0)
{
	$mapper = new mapper;
	$result = $mapper->get_all_ranks();
	if($result != false)
	{
		echo '
			<select name="rank" class="text ui-widget-content ui-corner-all" style="width: 100%">
		';
		while($row = mysql_fetch_array($result))
		{
			if($rank == $row["id"]) echo '<option value="'.$row["id"].'" selected>'.$row["name"].'</option>';
			else echo '<option value="'.$row["id"].'">'.$row["name"].'</option>';
		}
		echo '</select>';
	}
	else
	{

	}
}

?>